package com.auxgroup.hr.front.site.co.process;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import com.auxgroup.hr.front.site.co.BaseWfCO;
import com.auxgroup.hr.front.site.inteceptor.SessionGain;
import com.auxgroup.hr.front.site.vo.process.WfTlcHdrRespVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.BaseRetCode;
import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCAppStepInst;
import com.auxgroup.hr.front.dao.domain.PsCWfTlcHdr;
import com.auxgroup.hr.front.dao.domain.PsRsActDtlTbl;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.process.ProcessService;
import com.auxgroup.hr.front.service.process.WfFileService;
import com.auxgroup.hr.front.service.process.WfTlcHdrService;
import com.auxgroup.hr.front.site.co.BaseCO;
import com.auxgroup.hr.front.site.inteceptor.SessionGain;
import com.auxgroup.hr.front.site.vo.process.WfTlcHdrRespVO;

/**
 * 解除劳动合同审批流程
 * @author wangchangyun
 * @version 创建时间：180601 
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/wfTlcHdr")
public class WfTlcHdrCO extends BaseWfCO {

	private static final Logger logger = LoggerFactory.getLogger(WfTlcHdrCO.class);

	@Autowired
	public WfTlcHdrService wfTlcHdrService;
	

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	/**
	 * 获取解除劳动合同详情
	 * @param hireId
	 * @return
	 */
	@GetMapping(value = "/getTlcInfo")
	public BaseResponseVO getOne(String cTransactionNbr,@SessionGain("user") UserDTO user) {
		logger.info("getWfDmcHdr param= {}", cTransactionNbr);
		PsCWfTlcHdr wfTlcHdr = wfTlcHdrService.getWfTlcHdr(cTransactionNbr);
		if (wfTlcHdr == null) {
			return buildRespone(BaseRetCode.CODE_ERROR_PROCESS_NOT_EXIST);
		}
		WfTlcHdrRespVO respVo = objectMapper.map(wfTlcHdr, WfTlcHdrRespVO.class);
		buildTerDetail(wfTlcHdr.getRsTerDetail(),wfTlcHdr.getActionReason(),respVo);
		fillBaseWfInfo(user, wfTlcHdr, respVo);
		return buildRespone(respVo,false);
	}
	
	
	private void buildTerDetail(String terDetail,String actionReason,WfTlcHdrRespVO respVo){
		List<PsRsActDtlTbl> details =sysDictService.getTerDetails(actionReason);
		if(details!=null&&!details.isEmpty()){
			for (PsRsActDtlTbl detail : details) {
				if(detail.getRsTerDetail().equals(terDetail)){
					respVo.setRsTerDetail(detail.getDescr());
				}
			}
		}
	}

	@Override
	protected Set<String> getAuthFileds() {
		return null;
	}
}
